<?php

namespace App\Modules\System\Models;


use Illuminate\Database\Eloquent\Model;


class SetMedicinal extends Model
{
    protected $table = 'set_medicinal';

    protected $fillable = ['id','user_id', 'medicinal_id', 'meals', 'insulin_dosage', 'created_at', 'updated_at', 'status'];


    static function getList($param)
    {
        return self::from('set_medicinal AS S')->select(['S.id','S.user_id','S.medicinal_id','S.meals','S.insulin_dosage','S.status','M.medicinal_cn'])->leftJoin('medicinal AS M','M.id','=','S.medicinal_id')
            ->where('S.user_id',$param['user_id'])->where('S.status',1)->get()->toArray();
    }


    static function getSetMedicinal($id)
    {
        return self::where('id',$id)->first();
    }


    static function addSetMedicinal($param)
    {
        // TODO check
        return self::create($param);
    }


    static function updateSetMedicinal($param)
    {
        // TODO check
        return self::where('id',$param['id'])->update($param);
    }

    static function getCount($param){
        return self::where('user_id',$param['user_id'])->where('status',1)->groupBy($param['fields'])->get();
    }

}